﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace X22.DB.Extension.DBContext
{
    ///// <summary>
    ///// 数据库上下文
    ///// </summary>
    //public class X22DBContext : DbContext
    //{
    //    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    //    {
    //        optionsBuilder.UseMySQL("server=127.0.0.1;port=3306;database=md5data;uid=sa;pwd=123;");
    //    }
    //    public virtual DbSet<Md5Data> Md5Data { get; set; }
    //}
    public class X22DBContext : DbContext
    {
        //public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); });


        public X22DBContext(DbContextOptions<X22DBContext> options) : base(options)
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //optionsBuilder.UseLoggerFactory(MyLoggerFactory);
            base.OnConfiguring(optionsBuilder);

        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.ApplyConfiguration(new SysUserMap());
            //base.OnModelCreating(modelBuilder);

            //modelBuilder.ApplyConfigurationsFromAssembly(Assembly.Load("配置类所在dll名"));

            //modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
        }
        //数据库迁移
        //get-help entityframeworkcore
        //Add-Migration init（执行此命令项目生成一个目录（Migration））
        //Update-Database init
    }
}
